{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "问题描述\n",
    "请在Capital Bikeshare （美国Washington, D.C.的一个共享单车公司）提供的自行车数据上进行回归分析。训练数据为2011年的数据，要求预测2012年每天的单车共享数量。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.导入工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "UsageError: unrecognized arguments: 图形出现在Notebook里而不是新窗口\n"
     ]
    }
   ],
   "source": [
    "import numpy as np# 矩阵操作\n",
    "import pandas as pd# SQL数据处理\n",
    "\n",
    "#from sklearn import datasets, linear_model\n",
    "from sklearn.linear_model import LassoCV #lasso 回归\n",
    "from sklearn import metrics\n",
    "from sklearn import preprocessing\n",
    "from sklearn.linear_model import  RidgeCV #岭回归\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "import matplotlib.pyplot as plt# 画图可视化\n",
    "import seaborn as sns# 数据可视化工具包\n",
    "\n",
    "%matplotlib inline# 图形出现在Notebook里而不是新窗口"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.数据处理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.1.导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>dteday</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2011-01-01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2011-01-02</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2011-01-03</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2011-01-04</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2011-01-05</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
       "0        1  2011-01-01       1   0     1        0        6           0   \n",
       "1        2  2011-01-02       1   0     1        0        0           0   \n",
       "2        3  2011-01-03       1   0     1        0        1           1   \n",
       "3        4  2011-01-04       1   0     1        0        2           1   \n",
       "4        5  2011-01-05       1   0     1        0        3           1   \n",
       "\n",
       "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
       "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
       "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
       "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
       "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
       "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
       "\n",
       "    cnt  \n",
       "0   985  \n",
       "1   801  \n",
       "2  1349  \n",
       "3  1562  \n",
       "4  1600  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2.1.导入数据\n",
    "'''\n",
    "方法1：绝对路径调用\n",
    "set path to where the data of bike-sharing-set\n",
    "dpath = 'D:/jupyter/'\n",
    "data = pd.read_csv(dpath + \"day.csv\")\n",
    "'''\n",
    "#方法2：相对路径调用，要求文件必须处于相对路径在的文件夹\n",
    "dpath='./data/'\n",
    "data=pd.read_csv(dpath+\"day.csv\")\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(731, 16)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "instant       0\n",
       "dteday        0\n",
       "season        0\n",
       "yr            0\n",
       "mnth          0\n",
       "holiday       0\n",
       "weekday       0\n",
       "workingday    0\n",
       "weathersit    0\n",
       "temp          0\n",
       "atemp         0\n",
       "hum           0\n",
       "windspeed     0\n",
       "casual        0\n",
       "registered    0\n",
       "cnt           0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断数据有无空值\n",
    "data.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删去不用的特征及预测值已经经过数据探索不用的特征\n",
    "data = data.drop(columns=['instant','casual','registered','dteday','mnth','temp'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "类别型特征处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "season属性的不同取值和次数:\n",
      "3    188\n",
      "2    184\n",
      "1    181\n",
      "4    178\n",
      "Name: season, dtype: int64\n",
      "weathersit属性的不同取值和次数:\n",
      "1    463\n",
      "2    247\n",
      "3     21\n",
      "Name: weathersit, dtype: int64\n",
      "weekday属性的不同取值和次数:\n",
      "6    105\n",
      "1    105\n",
      "0    105\n",
      "5    104\n",
      "4    104\n",
      "3    104\n",
      "2    104\n",
      "Name: weekday, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "cate_features = [\"season\",\"weathersit\",\"weekday\"]\n",
    "for col in cate_features:\n",
    "    print(\"%s属性的不同取值和次数:\" % col)\n",
    "    print(data[col].value_counts())\n",
    "    data[col] = data[col].astype('object')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   season_1  season_2  season_3  season_4  weathersit_1  weathersit_2  \\\n",
      "0         1         0         0         0             0             1   \n",
      "1         1         0         0         0             0             1   \n",
      "2         1         0         0         0             1             0   \n",
      "3         1         0         0         0             1             0   \n",
      "4         1         0         0         0             1             0   \n",
      "\n",
      "   weathersit_3  weekday_0  weekday_1  weekday_2  weekday_3  weekday_4  \\\n",
      "0             0          0          0          0          0          0   \n",
      "1             0          1          0          0          0          0   \n",
      "2             0          0          1          0          0          0   \n",
      "3             0          0          0          1          0          0   \n",
      "4             0          0          0          0          1          0   \n",
      "\n",
      "   weekday_5  weekday_6  \n",
      "0          0          1  \n",
      "1          0          0  \n",
      "2          0          0  \n",
      "3          0          0  \n",
      "4          0          0  \n"
     ]
    }
   ],
   "source": [
    "#特征处理\n",
    "x_train_cat = data[cate_features]\n",
    "x_train_cat = pd.get_dummies(x_train_cat) #Pandas中的get_dummies()可对类别型特征进行one-hot编码\n",
    "x_train_cat.head()\n",
    "df = pd.DataFrame(x_train_cat)\n",
    "df.to_csv(\"D:/meng.csv\")\n",
    "print(x_train_cat.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           x0        x1      x0^2     x0 x1      x1^2      x0^3   x0^2 x1  \\\n",
      "0    0.805833  0.160446  0.649367  0.129293  0.025743  0.523281  0.104188   \n",
      "1    0.696087  0.248539  0.484537  0.173005  0.061772  0.337280  0.120426   \n",
      "2    0.437273  0.248309  0.191208  0.108579  0.061657  0.083610  0.047479   \n",
      "3    0.590435  0.160296  0.348613  0.094644  0.025695  0.205834  0.055881   \n",
      "4    0.436957  0.186900  0.190931  0.081667  0.034932  0.083429  0.035685   \n",
      "5    0.518261  0.089565  0.268594  0.046418  0.008022  0.139202  0.024057   \n",
      "6    0.498696  0.168726  0.248698  0.084143  0.028468  0.124025  0.041962   \n",
      "7    0.535833  0.266804  0.287117  0.142962  0.071184  0.153847  0.076604   \n",
      "8    0.434167  0.361950  0.188501  0.157147  0.131008  0.081841  0.068228   \n",
      "9    0.482917  0.223267  0.233209  0.107819  0.049848  0.112621  0.052068   \n",
      "10   0.686364  0.122132  0.471096  0.083827  0.014916  0.323343  0.057536   \n",
      "11   0.599545  0.304627  0.359454  0.182638  0.092798  0.215509  0.109499   \n",
      "12   0.470417  0.301000  0.221292  0.141596  0.090601  0.104100  0.066609   \n",
      "13   0.537826  0.126548  0.289257  0.068061  0.016014  0.155570  0.036605   \n",
      "14   0.498750  0.157963  0.248752  0.078784  0.024952  0.124065  0.039294   \n",
      "15   0.483750  0.188433  0.234014  0.091154  0.035507  0.113204  0.044096   \n",
      "16   0.537500  0.194017  0.288906  0.104284  0.037643  0.155287  0.056053   \n",
      "17   0.861667  0.146775  0.742470  0.126471  0.021543  0.639762  0.108976   \n",
      "18   0.741739  0.208317  0.550177  0.154517  0.043396  0.408088  0.114611   \n",
      "19   0.538333  0.195904  0.289802  0.105462  0.038378  0.156010  0.056773   \n",
      "20   0.457083  0.353242  0.208925  0.161461  0.124780  0.095496  0.073801   \n",
      "21   0.400000  0.171970  0.160000  0.068788  0.029574  0.064000  0.027515   \n",
      "22   0.436522  0.246600  0.190551  0.107646  0.060812  0.083180  0.046990   \n",
      "23   0.491739  0.158330  0.241807  0.077857  0.025068  0.118906  0.038285   \n",
      "24   0.616957  0.129796  0.380636  0.080079  0.016847  0.234836  0.049405   \n",
      "25   0.862500  0.293850  0.743906  0.253446  0.086348  0.641619  0.218597   \n",
      "26   0.687500  0.113837  0.472656  0.078263  0.012959  0.324951  0.053806   \n",
      "27   0.793043  0.123300  0.628917  0.097782  0.015203  0.498758  0.077545   \n",
      "28   0.651739  0.145365  0.424764  0.094740  0.021131  0.276835  0.061746   \n",
      "29   0.722174  0.073983  0.521535  0.053428  0.005473  0.376639  0.038585   \n",
      "..        ...       ...       ...       ...       ...       ...       ...   \n",
      "701  0.823333  0.124379  0.677877  0.102405  0.015470  0.558119  0.084314   \n",
      "702  0.767500  0.082721  0.589056  0.063488  0.006843  0.452101  0.048727   \n",
      "703  0.733750  0.174129  0.538389  0.127767  0.030321  0.395043  0.093749   \n",
      "704  0.485000  0.324021  0.235225  0.157150  0.104990  0.114084  0.076218   \n",
      "705  0.508750  0.174754  0.258827  0.088906  0.030539  0.131678  0.045231   \n",
      "706  0.764167  0.130600  0.583951  0.099800  0.017056  0.446236  0.076264   \n",
      "707  0.911250  0.101379  0.830377  0.092382  0.010278  0.756681  0.084183   \n",
      "708  0.905417  0.157975  0.819780  0.143033  0.024956  0.742243  0.129505   \n",
      "709  0.925000  0.190308  0.855625  0.176035  0.036217  0.791453  0.162832   \n",
      "710  0.596667  0.296037  0.356012  0.176636  0.087638  0.212420  0.105393   \n",
      "711  0.538333  0.162937  0.289802  0.087714  0.026548  0.156010  0.047220   \n",
      "712  0.485833  0.174129  0.236034  0.084598  0.030321  0.114673  0.041100   \n",
      "713  0.642917  0.131229  0.413342  0.084369  0.017221  0.265745  0.054242   \n",
      "714  0.650417  0.106350  0.423042  0.069172  0.011310  0.275154  0.044991   \n",
      "715  0.838750  0.100742  0.703502  0.084497  0.010149  0.590062  0.070872   \n",
      "716  0.907083  0.098258  0.822800  0.089128  0.009655  0.746348  0.080847   \n",
      "717  0.666250  0.221404  0.443889  0.147510  0.049020  0.295741  0.098279   \n",
      "718  0.625417  0.184092  0.391146  0.115134  0.033890  0.244630  0.072007   \n",
      "719  0.667917  0.132463  0.446113  0.088474  0.017546  0.297967  0.059093   \n",
      "720  0.556667  0.374383  0.309878  0.208407  0.140163  0.172499  0.116013   \n",
      "721  0.441250  0.407346  0.194702  0.179741  0.165931  0.085912  0.079311   \n",
      "722  0.515417  0.133083  0.265655  0.068593  0.017711  0.136923  0.035354   \n",
      "723  0.791304  0.077230  0.626162  0.061113  0.005965  0.495485  0.048359   \n",
      "724  0.734783  0.168726  0.539906  0.123977  0.028468  0.396714  0.091096   \n",
      "725  0.823333  0.316546  0.677877  0.260623  0.100201  0.558119  0.214579   \n",
      "726  0.652917  0.350133  0.426301  0.228608  0.122593  0.278339  0.149262   \n",
      "727  0.590000  0.155471  0.348100  0.091728  0.024171  0.205379  0.054119   \n",
      "728  0.752917  0.124383  0.566884  0.093650  0.015471  0.426817  0.070511   \n",
      "729  0.483333  0.350754  0.233611  0.169531  0.123028  0.112912  0.081940   \n",
      "730  0.577500  0.154846  0.333506  0.089424  0.023977  0.192600  0.051642   \n",
      "\n",
      "      x0 x1^2      x1^3      x0^4   x0^3 x1  x0^2 x1^2   x0 x1^3      x1^4  \n",
      "0    0.020744  0.004130  0.421677  0.083958   0.016717  0.003328  0.000663  \n",
      "1    0.042998  0.015353  0.234776  0.083827   0.029931  0.010687  0.003816  \n",
      "2    0.026961  0.015310  0.036560  0.020761   0.011789  0.006695  0.003802  \n",
      "3    0.015171  0.004119  0.121531  0.032994   0.008958  0.002432  0.000660  \n",
      "4    0.015264  0.006529  0.036455  0.015593   0.006670  0.002853  0.001220  \n",
      "5    0.004157  0.000718  0.072143  0.012468   0.002155  0.000372  0.000064  \n",
      "6    0.014197  0.004803  0.061851  0.020926   0.007080  0.002395  0.000810  \n",
      "7    0.038143  0.018992  0.082436  0.041047   0.020438  0.010177  0.005067  \n",
      "8    0.056879  0.047418  0.035533  0.029622   0.024695  0.020587  0.017163  \n",
      "9    0.024073  0.011129  0.054386  0.025144   0.011625  0.005375  0.002485  \n",
      "10   0.010238  0.001822  0.221931  0.039491   0.007027  0.001250  0.000222  \n",
      "11   0.055636  0.028269  0.129207  0.065650   0.033356  0.016948  0.008611  \n",
      "12   0.042620  0.027271  0.048970  0.031334   0.020049  0.012829  0.008209  \n",
      "13   0.008613  0.002027  0.083669  0.019687   0.004632  0.001090  0.000256  \n",
      "14   0.012445  0.003942  0.061877  0.019598   0.006207  0.001966  0.000623  \n",
      "15   0.017177  0.006691  0.054763  0.021331   0.008309  0.003237  0.001261  \n",
      "16   0.020233  0.007303  0.083467  0.030128   0.010875  0.003926  0.001417  \n",
      "17   0.018563  0.003162  0.551262  0.093901   0.015995  0.002725  0.000464  \n",
      "18   0.032188  0.009040  0.302694  0.085012   0.023875  0.006705  0.001883  \n",
      "19   0.020660  0.007518  0.083985  0.030563   0.011122  0.004047  0.001473  \n",
      "20   0.057035  0.044078  0.043650  0.033733   0.026070  0.020147  0.015570  \n",
      "21   0.011829  0.005086  0.025600  0.011006   0.004732  0.002034  0.000875  \n",
      "22   0.026546  0.014996  0.036310  0.020512   0.011588  0.006546  0.003698  \n",
      "23   0.012327  0.003969  0.058471  0.018826   0.006062  0.001952  0.000628  \n",
      "24   0.010394  0.002187  0.144884  0.030481   0.006413  0.001349  0.000284  \n",
      "25   0.074475  0.025373  0.553397  0.188540   0.064235  0.021884  0.007456  \n",
      "26   0.008909  0.001475  0.223404  0.036991   0.006125  0.001014  0.000168  \n",
      "27   0.012057  0.001875  0.395537  0.061497   0.009561  0.001487  0.000231  \n",
      "28   0.013772  0.003072  0.180424  0.040242   0.008976  0.002002  0.000447  \n",
      "29   0.003953  0.000405  0.271999  0.027865   0.002855  0.000292  0.000030  \n",
      "..        ...       ...       ...       ...        ...       ...       ...  \n",
      "701  0.012737  0.001924  0.459518  0.069418   0.010487  0.001584  0.000239  \n",
      "702  0.005252  0.000566  0.346987  0.037398   0.004031  0.000434  0.000047  \n",
      "703  0.022248  0.005280  0.289863  0.068788   0.016324  0.003874  0.000919  \n",
      "704  0.050920  0.034019  0.055331  0.036966   0.024696  0.016499  0.011023  \n",
      "705  0.015537  0.005337  0.066991  0.023011   0.007904  0.002715  0.000933  \n",
      "706  0.013034  0.002228  0.340999  0.058278   0.009960  0.001702  0.000291  \n",
      "707  0.009366  0.001042  0.689525  0.076712   0.008534  0.000949  0.000106  \n",
      "708  0.022596  0.003942  0.672039  0.117256   0.020459  0.003570  0.000623  \n",
      "709  0.033501  0.006892  0.732094  0.150620   0.030988  0.006375  0.001312  \n",
      "710  0.052291  0.025944  0.126744  0.062884   0.031200  0.015480  0.007680  \n",
      "711  0.014292  0.004326  0.083985  0.025420   0.007694  0.002329  0.000705  \n",
      "712  0.014731  0.005280  0.055712  0.019968   0.007157  0.002565  0.000919  \n",
      "713  0.011072  0.002260  0.170852  0.034873   0.007118  0.001453  0.000297  \n",
      "714  0.007356  0.001203  0.178965  0.029263   0.004785  0.000782  0.000128  \n",
      "715  0.008512  0.001022  0.494914  0.059444   0.007140  0.000858  0.000103  \n",
      "716  0.008758  0.000949  0.676999  0.073335   0.007944  0.000861  0.000093  \n",
      "717  0.032659  0.010853  0.197037  0.065478   0.021759  0.007231  0.002403  \n",
      "718  0.021195  0.006239  0.152996  0.045034   0.013256  0.003902  0.001149  \n",
      "719  0.011720  0.002324  0.199017  0.039470   0.007828  0.001552  0.000308  \n",
      "720  0.078024  0.052475  0.096024  0.064581   0.043433  0.029211  0.019646  \n",
      "721  0.073217  0.067591  0.037909  0.034996   0.032307  0.029825  0.027533  \n",
      "722  0.009129  0.002357  0.070572  0.018222   0.004705  0.001215  0.000314  \n",
      "723  0.004720  0.000461  0.392079  0.038266   0.003735  0.000365  0.000036  \n",
      "724  0.020918  0.004803  0.291499  0.066936   0.015370  0.003529  0.000810  \n",
      "725  0.082499  0.031718  0.459518  0.176670   0.067924  0.026115  0.010040  \n",
      "726  0.080043  0.042924  0.181732  0.097456   0.052262  0.028026  0.015029  \n",
      "727  0.014261  0.003758  0.121174  0.031930   0.008414  0.002217  0.000584  \n",
      "728  0.011648  0.001924  0.321357  0.053089   0.008770  0.001449  0.000239  \n",
      "729  0.059464  0.043153  0.054574  0.039604   0.028741  0.020857  0.015136  \n",
      "730  0.013847  0.003713  0.111226  0.029823   0.007997  0.002144  0.000575  \n",
      "\n",
      "[731 rows x 14 columns]\n"
     ]
    }
   ],
   "source": [
    "#对数据进行归一化处理\n",
    "from sklearn.preprocessing import PolynomialFeatures #用多项式做数值型数据处理\n",
    "numerical_features = [\"hum\",\"windspeed\"] #temp事先已被删除了\n",
    "poly = PolynomialFeatures(degree=4, include_bias=False, interaction_only=False)\n",
    "X_ploly = poly.fit_transform(data[numerical_features])\n",
    "X_ploly_df = pd.DataFrame(X_ploly, columns=poly.get_feature_names())\n",
    "print(X_ploly_df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将前边的特征值和4种数值值进行拼接生成一个新的data结果集\n",
    "\n",
    "x_train = pd.concat([x_train_cat,X_ploly_df,data['holiday'],data['workingday']],axis=1,ignore_index=False)\n",
    "df = pd.DataFrame(x_train)\n",
    "df.to_csv(\"D:/meng2.csv\")\n",
    "final_train = pd.concat([x_train,data['yr'],data['cnt']],axis=1,ignore_index=False)\n",
    "\n",
    "df = pd.DataFrame(final_train)\n",
    "df.to_csv(dpath+\"final.csv\",index=False)\n",
    "final_train.head()\n",
    "\n",
    "#加载生成的特征csv\n",
    "\n",
    "tz_data = pd.read_csv(dpath+\"final.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.2.数据分割（分为训练集和测试集）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>season_1</th>\n",
       "      <th>season_2</th>\n",
       "      <th>season_3</th>\n",
       "      <th>season_4</th>\n",
       "      <th>weathersit_1</th>\n",
       "      <th>weathersit_2</th>\n",
       "      <th>weathersit_3</th>\n",
       "      <th>weekday_0</th>\n",
       "      <th>weekday_1</th>\n",
       "      <th>weekday_2</th>\n",
       "      <th>...</th>\n",
       "      <th>x0 x1^2</th>\n",
       "      <th>x1^3</th>\n",
       "      <th>x0^4</th>\n",
       "      <th>x0^3 x1</th>\n",
       "      <th>x0^2 x1^2</th>\n",
       "      <th>x0 x1^3</th>\n",
       "      <th>x1^4</th>\n",
       "      <th>holiday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>yr</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.020744</td>\n",
       "      <td>0.004130</td>\n",
       "      <td>0.421677</td>\n",
       "      <td>0.083958</td>\n",
       "      <td>0.016717</td>\n",
       "      <td>0.003328</td>\n",
       "      <td>0.000663</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.042998</td>\n",
       "      <td>0.015353</td>\n",
       "      <td>0.234776</td>\n",
       "      <td>0.083827</td>\n",
       "      <td>0.029931</td>\n",
       "      <td>0.010687</td>\n",
       "      <td>0.003816</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.026961</td>\n",
       "      <td>0.015310</td>\n",
       "      <td>0.036560</td>\n",
       "      <td>0.020761</td>\n",
       "      <td>0.011789</td>\n",
       "      <td>0.006695</td>\n",
       "      <td>0.003802</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0.015171</td>\n",
       "      <td>0.004119</td>\n",
       "      <td>0.121531</td>\n",
       "      <td>0.032994</td>\n",
       "      <td>0.008958</td>\n",
       "      <td>0.002432</td>\n",
       "      <td>0.000660</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0.015264</td>\n",
       "      <td>0.006529</td>\n",
       "      <td>0.036455</td>\n",
       "      <td>0.015593</td>\n",
       "      <td>0.006670</td>\n",
       "      <td>0.002853</td>\n",
       "      <td>0.001220</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 31 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   season_1  season_2  season_3  season_4  weathersit_1  weathersit_2  \\\n",
       "0         1         0         0         0             0             1   \n",
       "1         1         0         0         0             0             1   \n",
       "2         1         0         0         0             1             0   \n",
       "3         1         0         0         0             1             0   \n",
       "4         1         0         0         0             1             0   \n",
       "\n",
       "   weathersit_3  weekday_0  weekday_1  weekday_2 ...   x0 x1^2      x1^3  \\\n",
       "0             0          0          0          0 ...  0.020744  0.004130   \n",
       "1             0          1          0          0 ...  0.042998  0.015353   \n",
       "2             0          0          1          0 ...  0.026961  0.015310   \n",
       "3             0          0          0          1 ...  0.015171  0.004119   \n",
       "4             0          0          0          0 ...  0.015264  0.006529   \n",
       "\n",
       "       x0^4   x0^3 x1  x0^2 x1^2   x0 x1^3      x1^4  holiday  workingday  yr  \n",
       "0  0.421677  0.083958   0.016717  0.003328  0.000663        0           0   0  \n",
       "1  0.234776  0.083827   0.029931  0.010687  0.003816        0           0   0  \n",
       "2  0.036560  0.020761   0.011789  0.006695  0.003802        0           1   0  \n",
       "3  0.121531  0.032994   0.008958  0.002432  0.000660        0           1   0  \n",
       "4  0.036455  0.015593   0.006670  0.002853  0.001220        0           1   0  \n",
       "\n",
       "[5 rows x 31 columns]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2.2.数据分割\n",
    "# 从原始数据中分离输入特征X和输出y\n",
    "y = tz_data['cnt'].values # 根据作业说明文档，casual、registered、cnt都是输出y，但作业只需对cnt进行预测\n",
    "X = tz_data.drop('cnt',axis=1)\n",
    "\n",
    "\n",
    "# 用于后续显示权重系数对应的特征\n",
    "columns = X.columns\n",
    "\n",
    "X.head()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.\n",
      "  \"This module will be removed in 0.20.\", DeprecationWarning)\n"
     ]
    }
   ],
   "source": [
    "# 将数据分割训练数据与测试数据 # 根据作业要求，2011年数据作为训练样本，2012年数据作为测试样本\n",
    "from sklearn.cross_validation import train_test_split\n",
    "\n",
    "X_train = X[X.yr==0]\n",
    "X_test = X[X.yr==1]\n",
    "\n",
    "y_train = data[data.yr==0]['cnt'].values\n",
    "y_test = data[data.yr==1]['cnt'].values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.3数据归一化处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to float64 by the scale function.\n",
      "  warnings.warn(msg, DataConversionWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\utils\\validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to float64 by the scale function.\n",
      "  warnings.warn(msg, DataConversionWarning)\n"
     ]
    }
   ],
   "source": [
    "from sklearn import preprocessing\n",
    "\n",
    "X_train = preprocessing.scale(X_train)\n",
    "X_test = preprocessing.scale(X_test)\n",
    "\n",
    "y_train = preprocessing.scale(y_train)\n",
    "y_test = preprocessing.scale(y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.确定模型类型 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>x0^2</td>\n",
       "      <td>20.314643</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>x0 x1</td>\n",
       "      <td>15.986703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>x1^2</td>\n",
       "      <td>7.594258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>x0^3 x1</td>\n",
       "      <td>7.107186</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>x0^2 x1^2</td>\n",
       "      <td>2.344773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>x0^4</td>\n",
       "      <td>2.172674</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>x1^4</td>\n",
       "      <td>0.879806</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>x0 x1^3</td>\n",
       "      <td>0.605753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>season_3</td>\n",
       "      <td>0.320884</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>season_2</td>\n",
       "      <td>0.135365</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>0.112990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>season_4</td>\n",
       "      <td>0.083141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>weekday_6</td>\n",
       "      <td>0.026278</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>weekday_2</td>\n",
       "      <td>0.022450</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>workingday</td>\n",
       "      <td>0.017185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>weekday_5</td>\n",
       "      <td>0.002564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>weekday_3</td>\n",
       "      <td>0.001998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>yr</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>weekday_4</td>\n",
       "      <td>-0.002650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-0.019990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-0.030860</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>-0.039271</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>holiday</td>\n",
       "      <td>-0.039545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-0.182697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>season_1</td>\n",
       "      <td>-0.544734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>x1^3</td>\n",
       "      <td>-3.765070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>x0 x1^2</td>\n",
       "      <td>-6.118034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>x1</td>\n",
       "      <td>-7.414395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>x0</td>\n",
       "      <td>-9.511403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>x0^3</td>\n",
       "      <td>-13.490604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>x0^2 x1</td>\n",
       "      <td>-17.976425</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns       coef\n",
       "16          x0^2  20.314643\n",
       "17         x0 x1  15.986703\n",
       "18          x1^2   7.594258\n",
       "24       x0^3 x1   7.107186\n",
       "25     x0^2 x1^2   2.344773\n",
       "23          x0^4   2.172674\n",
       "27          x1^4   0.879806\n",
       "26       x0 x1^3   0.605753\n",
       "2       season_3   0.320884\n",
       "1       season_2   0.135365\n",
       "4   weathersit_1   0.112990\n",
       "3       season_4   0.083141\n",
       "13     weekday_6   0.026278\n",
       "9      weekday_2   0.022450\n",
       "29    workingday   0.017185\n",
       "12     weekday_5   0.002564\n",
       "10     weekday_3   0.001998\n",
       "30            yr   0.000000\n",
       "11     weekday_4  -0.002650\n",
       "8      weekday_1  -0.019990\n",
       "7      weekday_0  -0.030860\n",
       "5   weathersit_2  -0.039271\n",
       "28       holiday  -0.039545\n",
       "6   weathersit_3  -0.182697\n",
       "0       season_1  -0.544734\n",
       "22          x1^3  -3.765070\n",
       "21       x0 x1^2  -6.118034\n",
       "15            x1  -7.414395\n",
       "14            x0  -9.511403\n",
       "19          x0^3 -13.490604\n",
       "20       x0^2 x1 -17.976425"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 模型：使用默认配置初始化（生成学习器实例）\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数（模型训练）\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "# 看看各特征的权重系数， 系数的绝对值大小可视为该特征的重要性\n",
    "#dataframe中index用来标识行，column标识列\n",
    "#coef是提取模型训练出来的权重参数，“coef_”是获取训练好的模型的权重，T是转置为列向量\n",
    "fs=pd.DataFrame({\"columns\":list(columns),\"coef\":list(lr.coef_.T)})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.4287040204316266\n",
      "The r2 score of LinearRegression on train is 0.7214141534851409\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果(print后面注意加括号)\n",
    "# 测试集\n",
    "print ('The r2 score of LinearRegression on test is',r2_score(y_test,y_test_pred_lr))\n",
    "# 训练集\n",
    "print ('The r2 score of LinearRegression on train is',r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0xb3bd208>"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAFsCAYAAADos0H8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHKJJREFUeJzt3XuUXGWZ7/HvA7SJEggEEgjEGFBAuXawCUQuhslwkQDBMyoyCHgIBBDWeMOjgEhk5IxzQB05IjOICAgigiJ40DNwIkyUUTDNCjcDJArRhEwIQSFBkCQ854/aHTqhO13pru5+0/39rNWrq/betd9nv1Xdv9qXeisyE0mSVJ5N+rsASZLUMUNakqRCGdKSJBXKkJYkqVCGtCRJhTKkJUkqlCGtAS8i/jUiLqxuT4qIhb3c3riIyIjYrIHrXBEROzdqfRvQ7lkRsaRqf5s+anNs1d6mncyfERE3NKitjIh3NGJdUm9o2D8Rqb9ExNPAdsBqYCXwn8CZmflHgMw8s/+qa4zMHNbXbUZEE/BV4IDMfKiD+eOAp4CXqknPAf+amV/uSbuZ+Qegz7dXKpF70hoojqmCbDSwBPjf/VxPQzRyb7wbtgOGAo91sdxWVd9/ALgwIg7r9cqkQcKQ1oCSma8AtwK7t02LiGsj4ksdLR8R/xARv42IMdX9oyNiTkT8OSL+MyL27qytiJgQEbMj4sXqkPBX11nkxIj4Q0Q8FxEXrPO4X1VtLI6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/+c3MmTOHRx99lBEjRnDFFVd0az1XX331GwK6BC0tLb0e0KtXr27o+gxpSdIbTJw4kUWLFq25f+mll7Lffvux9957c9FFFwHw0ksvMWXKFPbZZx/23HNPbr75ZqC2F9s2BPR3vvMddt11V9773vdy3333rVnfRz/6UW699dY194cNGwbAihUrmDx5Mvvuuy977bUXt99++xtqW7x4MYcccgjNzc3sueee/OIXv6hrm+69916OPvpoAGbMmMGpp57KpEmT2HnnndcK7xtuuIEJEybQ3NzMGWecsSZ4zzrrLFpaWthjjz3W9AHUhry++OKLOeigg7jlllvqqqVeHu6WJK1l9erVzJw5k2nTpgFw1113MW/ePB544AEyk2OPPZZZs2axdOlSdthhB+68804AXnjhhbXWs3jxYi666CJaW1sZPnw4hx56KOPHj19v20OHDuW2225jyy235LnnnuOAAw7g2GOPXesCrO9973scccQRXHDBBaxevZq//OUv3drOxx9/nHvuuYfly5ez2267cdZZZzF//nxuvvlm7rvvPpqamvjYxz7GjTfeyMknn8wll1zCiBEjWL16NZMnT+bhhx9m7733XlP3L3/5y27VsT6GtCQJgJdffpnm5maefvpp3v3ud3PYYYcBtZC+66671gTsihUrmDdvHgcffDDnnnsun/3sZzn66KM5+OCD11rf/fffz6RJkxg5svZlT8cffzxPPvnkemvITM4//3xmzZrFJptswqJFi1iyZAnbb7/9mmX2228/Tj31VFauXMlxxx1Hc3Nzt7Z3ypQpDBkyhCFDhjBq1CiWLFnCzJkzaW1tZb/99lvTJ6NGjQLgBz/4AVdddRWrVq1i8eLF/Pa3v10T0scff3y3auiKh7slScDr56QXLFjAq6++uuacdGZy3nnnMWfOHObMmcP8+fOZNm0au+66K62trey1116cd955XHzxxW9YZ2cfQdpss8147bXX1qz/1VdfBeDGG29k6dKltLa2MmfOHLbbbrs3fM74kEMOYdasWey4446cdNJJXH/99d3a3iFDhqy5vemmm7Jq1Soyk1NOOWXNtj7xxBPMmDGDp556issuu4yZM2fy8MMPM2XKlLXq2nzzzbtVQ1fck5YaqN4rcvvjyt3ealsD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ztZR9tr4/cRcS8wHhgIIV3Pc922zMKI2AwYTj8c9usDXfZFZi5rd/dbDNDz83UaUP8neiozX2x3+6cR8c2I2DYze/RFJB7urkTE5hGxRdtt4HBqF1kNRoNpyNc7gFOq26cAbzjSEBFbR8SQ6va2wIHAb/uswt5Vz3Pdvo8+APw8B+YoSF32xTrnXI8F5vZhfaW5Azi5usr7AOCFtlNHg1FEbN92rUZETKCWr8vW/6g6ZOaA/wHeT+1d31+BJcC/V9N3AH5a3d4ZeKj6eYzaoeF+r70/+qK6fxTwJLW9xQHZF9V2bkPtqu551e8R1fQW4Orq9nuAR6rXxiPAtP6uu8F98IbnGrgYOLa6PRS4BZgPPADs3N8192Nf/FP1/+Eh4B7gnf1dcy/2xU3AYmBl9T9jGnAmcGY1P6hdDf+76u+ipb9r7uf+OKfda+PXwHsa0a7DgkqSVCgPd0uSVChDWpKkQhnSkiQVypCWJKlQhrQkSYUypCVJKpQhLUlSof4/3T3MBGOwfREAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f,ax=plt.subplots(figsize=(7,5))#f,ax的全写是fig，ax，在matplotlib中，\n",
    "#整个图像为一个Figure对象。在Figure对象中可以包含一个或者多个Axes对象（图像）。每个Axes(ax)对象都是一个拥有自己坐标系统的绘图区域。\n",
    "f.tight_layout()#图像外部边缘调整（设置默认的间距）\n",
    "\n",
    "ax.set_title(\"Bike-sharing of Residuals\")\n",
    "#残差=真值（yTest）-预测值（y_test_pred_lr）\n",
    "#ax.hist画直方图 # bins 数据的宽度 alpha 频率分布图的透明度\n",
    "ax.hist(y_train - y_train_pred_lr,bins=40,label='Residuals Linear', color='b', alpha=.5);\n",
    "ax.legend(loc='best')#在合适的位置放置图例。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "有噪声。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJztnXl4lOXV/z8nw5CENawqEcStWNkXLZXXCrwiKCqLCyq1UFvUukuloohKXUCpy6+2tVJoVVxQAXmLVEFEcUVkicQKtoqARGULAYGQ9fz+mJkwSWZ5JjOTJ5mcz3XlYp6ZZ+77JGS+uc+5z32OqCqGYRjJIM1tAwzDSF1MYAzDSBomMIZhJA0TGMMwkoYJjGEYScMExjCMpGECYxhG0jCBMQwjaZjAGIaRNBq5bUAstG3bVjt37uy2GYbR4Fm7du1uVW0X7b56JTCdO3dmzZo1bpthGA0eEdnq5D5zkQzDSBomMIZhJA3XBEZEMkRktYh8KiL/FpFpbtliGEZycDMGUwQMVtUDIuIF3heR11V1lYs2GYaRQFxbwaiPA/5Lr//LitMYhgsUFxcnZVxXYzAi4hGRHGAn8KaqfhzinqtFZI2IrNm1a1ftG2kYKc6GDRvo27cvL7zwQsLHdlVgVLVMVXsBxwKni0i3EPfMUtV+qtqvXbuo2+6GYTikvLycRx99lNNOO43du3fTpk2bhM9RJ3aRVLUAeAcY5rIphtEg2L59O0OGDOG3v/0t5557Lhs2bGDo0KEJn8fNXaR2IpLlf5wJnA1scssew2hIfPLJJ3z88cfMnj2bV199lWR5B27uIh0DPCMiHnxC97KqvuaiPYaR0uzbt48PP/yQc889l1GjRrF582bat2+f1DldExhV3QD0dmt+w2hIvPfee1x55ZXs2rWLrVu30rZt26SLC9SRGIxhGMmhuLiYKVOmMHDgQDweD8uXL6dt27a1Nn+9OuxoGIZzSkpKOPPMM1m9ejW/+tWveOyxx2jevHmt2mArGMNIUbxeL6NGjWLBggXMnj271sUFTGAMI6XYsWMHI0aMYMWKFQBMnjyZ0aNHu2aPCYxhpAiLFy+me/fuLF26lG3btrltDmACYxj1noMHD3Lttddy4YUX0qFDB9auXcv48ePdNgswgTGMes9LL73ErFmz+N3vfsfHH39M165d3TapAttFMox6SFlZGRs3bqRbt26MHz+enj170rdvX7fNqoatYAyjnvH1119z1llnceaZZ7J7927S0tLqpLiACYxh1BtUlWeffZaePXuSm5vLn/70p6ScgE4k5iIZRj2gpKSEsWPH8sorr/Czn/2MZ599luOOO85ts6JiKxjDqAd4vV6aN2/O9OnTWbFiRb0QF7AVjGHUWQ4fPszUqVMZN24c3bp1Y/bs2YiI22bFhAmMYdRBcnNzGTt2LLm5ubRv355u3brVO3EBc5EMo05RXl7OY489Rr9+/dixYwdLlixh0qRJbptVY9ysaNdRRN4WkY3+vkg3u2WLYdQVZs+ezcSJExk2bBi5ubmcd955bpsUF266SKXAb1V1nYg0B9aKyJuq+rmLNhmGK+zZs4c2bdowbtw4WrZsyaWXXlovXaKquNkX6TtVXed//AOwEch2yx7DcIP9+/czfvx4+vTpw759+0hPT2fMmDEpIS5QR2IwItIZX/lM64tkNBjef/99evbsydy5cxk/fjxNmjRx26SE47rAiEgzYAFwi6rur/q69UUyUo3S0lLuuusuzjrrLNLS0nj//feZNm0aXq/XbdMSjtudHb34xOV5VV3opi2GUVukpaXx0UcfMW7cOHJycvjpT3/qtklJw7Ugr/iczDnARlV91C07DKM2UFXmzJnDueeeS3Z2NkuWLCEjI8Nts5KOmyuYAcCVwGARyfF/1e89OcMIwc6dOxkxYgQTJkzgySefBGgQ4gLu9kV6H0iNULlhhGHJkiVcddVV7Nu3j8cff5wbb7zRbZNqFTsqYBhJ4plnnmH8+PH06NGDt956i27durltUq3j+i6SYaQapaWlAIwYMYJp06axevXqBikuYAJjGAmjrKyM6dOnM2DAAIqLi8nKyuLuu+8mPT3dbdNcwwTGMBLAli1bGDhwIHfeeSedO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AM9zGBMQwjaZjAGIaRNExgDMNIGiYwhmEkDRMYAwARaeM/eZ4jIt+LSF7QdWMX7TpbRBa5Nb8RH/U6k9dIHKq6B+gFICL3AgdU9Q/B9/gTw0RVy6uPYBjVsRWMEREROcl/lumvwDqgo4gUBL1+mYjM9j8+SkQWisgaf32R/iHGW+PvSx64fl9EeopIfxH5SETWi8gHVTKxA/feLyK3BF1vEpFj/Y/H+efMEZG/iIj9btcB7D/BcMKpwBxV7Q1Eyob+I/Cw+vrqXArMDnHPS/7X8ItDG1X9FF+pgv/xz3EfcL9T4/wH80YBZ/gP7DXCdxTBcBlzkQwnfKWqnzi472ygi8+TAqCViGSqamHQPS8Di/GJyBj/NUAW8KyInFgD+84GTgPW+OfOpHJpCMMlTGAMJxwMelxO5dILGUGPBTjdX1AqJKq6VUQOiMip+ARmvP+lB4ClqvoXETkJeCPE20upvOoOzC34zjZNdfLNGLWHuUhGTPgDvHtF5GR/nGNU0MvLgesDFyLSK8wwLwF3AOmq+rn/uZYccb/Gh3nfFqCvf+zTOVL+YTlwqYi09b/WRkQ6xfBtGUnCBMaoCbfjW2G8ha/OS4DrgQHiK3D+OTAhzPtfAa7giHsEvnrFM0XkgwjzvgIcJSLrgV8BmwFUNReYBiwXkQ3AMuComL8rI+HYaWrDMJKGrWAMw0gaJjCGYSQNExjDMJKGCYxhGEnDBMYwjKRhAmMYRtIwgTEMI2n8f6YEWBvTrOdMAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 还可以观察预测值和真值的散点图\n",
    "plt.figure(figsize=(4,3))#figsize是图的大小\n",
    "plt.scatter(y_train,y_train_pred_lr) #括号里逗号前和逗号后是长度相同的数组序列\n",
    "plt.plot([-3,3],[-3,3],'--k') # 数据已归一化，三倍标准差即可，第一个[-3,3]：x轴坐标，第二个是y轴坐标，“--”是虚线，“k”是黑色\n",
    "plt.axis('tight')# 坐标轴适应数据量 axis 设置坐标轴。表明采用紧致方案,需要将样本的边缘作为画布的边缘。\n",
    "plt.xlabel('True value')\n",
    "plt.ylabel('Predicted value')\n",
    "plt.tight_layout()#图像外部边缘调整（设置默认的间距）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2正则化的线性回归（L2正则-->岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.6234225229464978\n",
      "The r2 score of RidgeCV on train is 0.7125842352317395\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None,  #cv：交叉验证，cv=None 留一交叉验证\n",
    "#                                  store_cv_values=False)\n",
    "#RidgeCV 实现了带缺省 \\alpha 参数的交叉验证的岭回归模型.\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  #store_cv_values=True：是否保存cv的值\n",
    "\n",
    "#模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge))\n",
    "print ('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEKCAYAAAA4t9PUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xd4VHXaxvHvkw5JIJTQCTW00IkgYK8oSrXA+qrr6ioKK65rwbL6WnZV3MWyYtfddS2oFMWKvaEoAUJC6IQWegkBEiDtef+YA+8sBhhIzpzJ5PlcV67MnDk5c88Rc+fUn6gqxhhjzImK8DqAMcaY6s2KxBhjTKVYkRhjjKkUKxJjjDGVYkVijDGmUqxIjDHGVIoViTHGmEqxIjHGGFMpViTGGGMqJcrrAMHQsGFDbd26tdcxjDGmWpk3b952VU0+1nw1okhat25NRkaG1zGMMaZaEZG1gcxnu7aMMcZUihWJMcaYSrEiMcYYUylWJMYYYyrFisQYY0ylWJEYY4ypFCsSY4wxlWJFcgSqyjtz1/NZzmavoxhjTEirERcknoiycuW1OWvYXLCfvm3qk1Q7xutIxhgTkmyL5AiiIiOYOLIHu4pKePDDxV7HMcaYkGVFchRdmtXhxjPaMX3+Br5ZttXrOMYYE5KsSI5h3Fntad8ogXtmLGLvgVKv4xhjTMixIjmG2KhIHhvZnY0F+5j46VKv4xhjTMixIglAn1b1+O2A1rz201p+Wb3T6zjGGBNSrEgCdPv5HWlRrxZ3Tstif0mZ13GMMSZkWJEEqHZMFI+O6M7q7YU8+cUKr+MYY0zIsCI5DqekNuTy9Ja89H0u2XkFXscxxpiQ4GqRiMggEVkmIitFZEIFr48RkWwRyRSRH0SkizO9tYjsc6Znisjzfj/Tx/mZlSLytIiIm5/hcHcP7kyD+BjumJZFSVl5MN/aGGNCkmtFIiKRwGTgAqALMPpgUfh5U1W7qWpPY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y/C/h9EB53sZ////7h/x3eOsB749DPv95o9zMhjjKtu1ZUxgvgMuF5FI57jFafhurvgDvoGfIkSkMb7hVg9aArR3HtcBCoECZ74LjvA+Efju/gvwG2f5R1MX2ORsEV2Jb/jcgzoQGnd/NmHOtkiMCcwMfMc/FuLbSrhDVTeLyDTgbHy/sJfjG5muwPmZj/AVyxequlBEFuC7O2wuMPsI71MIpInIPGc5lx8j17PANBG5FN/deQv9XjvTyWCMq+zuv8ZUkogkqG9UvAb4tlIGOiVTC98v94HOsZVAlrVXVROqKNd3wFBVza+K5RlzJLZFYkzlfSgiSUAM8JCqbgZQ1X0icj++sbHXBTOQs/ttkpWICQbbIjHGGFMpdrDdGGNMpViRGGOMqRQrEmOMMZViRWKMMaZSrEiMMcZUihWJMcaYSvk/BNVw8QPLxTQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is 10.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'参数说明\\naxis：0按照行名排序；1按照列名排序\\nlevel：默认None，否则按照给定的level顺序排列---貌似并不是，文档\\nascending：默认True升序排列；False降序排列\\ninplace：默认False，否则排序之后的数据直接替换原来的数据框\\nkind：默认quicksort，排序的方法\\nna_position：缺失值默认排在最后{\"first\",\"last\"}\\nby：按照那一列数据进行排序，但是by参数貌似不建议使用\\n'"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_,axis=0) #不同alphas交叉验证的均值\n",
    "plt.plot(np.log10(alphas),mse_mean.reshape(len(alphas),1)) #mse为平均平方误差，reshape函数用于重新调整矩阵的行数、列数、维数，但是元素个数不变。\n",
    "# len() 方法返回对象（字符、列表、元组等）长度或项目个数。\n",
    "#reshape(len(alphas),1):将前面矩阵的形状转为len（alphar）行，1列\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3),[0.28,0.29,0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alpha is',ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef_lr\":list((lr.coef_.T)),\"coef_ridge\":list(ridge.coef_.T)})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)\n",
    "#sort_values按照某一列的大小进行排序\n",
    "'''参数说明\n",
    "axis：0按照行名排序；1按照列名排序\n",
    "level：默认None，否则按照给定的level顺序排列---貌似并不是，文档\n",
    "ascending：默认True升序排列；False降序排列\n",
    "inplace：默认False，否则排序之后的数据直接替换原来的数据框\n",
    "kind：默认quicksort，排序的方法\n",
    "na_position：缺失值默认排在最后{\"first\",\"last\"}\n",
    "by：按照那一列数据进行排序，但是by参数貌似不建议使用\n",
    "'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.3正则化的线性回归（L1正则-->Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.6147457850536395\n",
      "The r2 score of LassoCV on train is 0.7093719561904199\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n",
      "D:\\Anaconda3\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:491: ConvergenceWarning: Objective did not converge. You might want to increase the number of iterations. Fitting data with very small alpha may cause precision problems.\n",
      "  ConvergenceWarning)\n"
     ]
    }
   ],
   "source": [
    "#Lasso / L1正则\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "\n",
    "# 设置超参数搜索范围\n",
    "# alphas=[0.01,0.1,1,10,100]\n",
    "\n",
    "# 生成一个LassoCV实例\n",
    "# lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "lasso = LassoCV()\n",
    "\n",
    "#训练（内含CV交叉验证）\n",
    "lasso.fit(X_train,y_train)\n",
    "\n",
    "#测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test,y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train,y_train_pred_lasso))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAEKCAYAAADn+anLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3Xt8XHWd//HXJ/fm0vSSpPcrvdAW2kJTbi1SLWJlBVRERESoYFldWXcfuisuu6Lr+lsRXV1dFVkFXBEQBeUiQgtCkWtJr/Te0kuSXpK0ubRJ2lxmPr8/ZoqhdNppmsmZmbyfj8c8MpfvnPmcTDLvOd/zPd9j7o6IiMixZARdgIiIJC+FhIiIxKSQEBGRmBQSIiISk0JCRERiUkiIiEhMCgkREYlJISEiIjEpJEREJKasoAs4WSUlJT527NigyxARSSnLly/f5+6lJ/u8lAuJsWPHUlFREXQZIiIpxcx2dud56m4SEZGYFBIiIhKTQkJERGJSSIiISEwKCRERiUkhISIiMSkkREQkJoWEiEgK+O9nt7B8Z0Ovv27KHUwnItLXrK5q5PvPbgZg1piBvfra2pIQEUlydz6ziUEFOdx44bhef22FhIhIEntl6z5e2rqPz887jcLc3u/8UUiIiCQpd+c7z2xiWHEenzpvTCA1KCRERJLUkvU1rKpq5IvzJ5KXnRlIDQkLCTO7x8xqzWztcdrMM7NVZrbOzJYmqhYRkVQTCjvfXbyJcSUFfGzWyMDqSOSWxH3AglgPmtkA4CfA5e4+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ehG4wiPnUhfpNdqSEHmnJ81sAJADfNPd9wK4+yEzu53IOYIre7OgaJfYfykgJAjakhARkZi041pERGJSSIiISEwKCRERiUkhISIiMSkkREQkJoWEiIjE9P8BtiySHynxtxQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is 0.005861087134472622\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>coef_lasso</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>x0^2</td>\n",
       "      <td>20.314643</td>\n",
       "      <td>0.104885</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>x0 x1</td>\n",
       "      <td>15.986703</td>\n",
       "      <td>-0.038799</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>x1^2</td>\n",
       "      <td>7.594258</td>\n",
       "      <td>0.097185</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>x0^3 x1</td>\n",
       "      <td>7.107186</td>\n",
       "      <td>-0.080691</td>\n",
       "      <td>-0.105296</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>x0^2 x1^2</td>\n",
       "      <td>2.344773</td>\n",
       "      <td>-0.053502</td>\n",
       "      <td>-0.078694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>x0^4</td>\n",
       "      <td>2.172674</td>\n",
       "      <td>-0.140031</td>\n",
       "      <td>-0.038076</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>x1^4</td>\n",
       "      <td>0.879806</td>\n",
       "      <td>-0.056738</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>x0 x1^3</td>\n",
       "      <td>0.605753</td>\n",
       "      <td>-0.064331</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>season_3</td>\n",
       "      <td>0.320884</td>\n",
       "      <td>0.306607</td>\n",
       "      <td>0.181702</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>season_2</td>\n",
       "      <td>0.135365</td>\n",
       "      <td>0.128304</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>weathersit_1</td>\n",
       "      <td>0.112990</td>\n",
       "      <td>0.113749</td>\n",
       "      <td>0.146047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>season_4</td>\n",
       "      <td>0.083141</td>\n",
       "      <td>0.090943</td>\n",
       "      <td>-0.023962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>weekday_6</td>\n",
       "      <td>0.026278</td>\n",
       "      <td>0.016374</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>weekday_2</td>\n",
       "      <td>0.022450</td>\n",
       "      <td>0.014043</td>\n",
       "      <td>0.008120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>workingday</td>\n",
       "      <td>0.017185</td>\n",
       "      <td>0.016730</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>weekday_5</td>\n",
       "      <td>0.002564</td>\n",
       "      <td>0.002858</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>weekday_3</td>\n",
       "      <td>0.001998</td>\n",
       "      <td>0.002589</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>yr</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>weekday_4</td>\n",
       "      <td>-0.002650</td>\n",
       "      <td>-0.001925</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>weekday_1</td>\n",
       "      <td>-0.019990</td>\n",
       "      <td>-0.011421</td>\n",
       "      <td>-0.005606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>weekday_0</td>\n",
       "      <td>-0.030860</td>\n",
       "      <td>-0.022648</td>\n",
       "      <td>-0.029669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>weathersit_2</td>\n",
       "      <td>-0.039271</td>\n",
       "      <td>-0.038007</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>holiday</td>\n",
       "      <td>-0.039545</td>\n",
       "      <td>-0.034457</td>\n",
       "      <td>-0.035826</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>weathersit_3</td>\n",
       "      <td>-0.182697</td>\n",
       "      <td>-0.187569</td>\n",
       "      <td>-0.184398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>season_1</td>\n",
       "      <td>-0.544734</td>\n",
       "      <td>-0.530909</td>\n",
       "      <td>-0.664760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>x1^3</td>\n",
       "      <td>-3.765070</td>\n",
       "      <td>0.048913</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>x0 x1^2</td>\n",
       "      <td>-6.118034</td>\n",
       "      <td>0.000170</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>x1</td>\n",
       "      <td>-7.414395</td>\n",
       "      <td>-0.006462</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>x0</td>\n",
       "      <td>-9.511403</td>\n",
       "      <td>0.152565</td>\n",
       "      <td>0.110920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>x0^3</td>\n",
       "      <td>-13.490604</td>\n",
       "      <td>-0.011150</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>x0^2 x1</td>\n",
       "      <td>-17.976425</td>\n",
       "      <td>-0.037699</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         columns    coef_lr  coef_ridge  coef_lasso\n",
       "16          x0^2  20.314643    0.104885    0.000000\n",
       "17         x0 x1  15.986703   -0.038799   -0.000000\n",
       "18          x1^2   7.594258    0.097185    0.000000\n",
       "24       x0^3 x1   7.107186   -0.080691   -0.105296\n",
       "25     x0^2 x1^2   2.344773   -0.053502   -0.078694\n",
       "23          x0^4   2.172674   -0.140031   -0.038076\n",
       "27          x1^4   0.879806   -0.056738   -0.000000\n",
       "26       x0 x1^3   0.605753   -0.064331   -0.000000\n",
       "2       season_3   0.320884    0.306607    0.181702\n",
       "1       season_2   0.135365    0.128304    0.000000\n",
       "4   weathersit_1   0.112990    0.113749    0.146047\n",
       "3       season_4   0.083141    0.090943   -0.023962\n",
       "13     weekday_6   0.026278    0.016374    0.000000\n",
       "9      weekday_2   0.022450    0.014043    0.008120\n",
       "29    workingday   0.017185    0.016730    0.000000\n",
       "12     weekday_5   0.002564    0.002858    0.000000\n",
       "10     weekday_3   0.001998    0.002589    0.000000\n",
       "30            yr   0.000000    0.000000    0.000000\n",
       "11     weekday_4  -0.002650   -0.001925   -0.000000\n",
       "8      weekday_1  -0.019990   -0.011421   -0.005606\n",
       "7      weekday_0  -0.030860   -0.022648   -0.029669\n",
       "5   weathersit_2  -0.039271   -0.038007   -0.000000\n",
       "28       holiday  -0.039545   -0.034457   -0.035826\n",
       "6   weathersit_3  -0.182697   -0.187569   -0.184398\n",
       "0       season_1  -0.544734   -0.530909   -0.664760\n",
       "22          x1^3  -3.765070    0.048913    0.000000\n",
       "21       x0 x1^2  -6.118034    0.000170   -0.000000\n",
       "15            x1  -7.414395   -0.006462   -0.000000\n",
       "14            x0  -9.511403    0.152565    0.110920\n",
       "19          x0^3 -13.490604   -0.011150   -0.000000\n",
       "20       x0^2 x1 -17.976425   -0.037699   -0.000000"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_,axis=1)\n",
    "plt.plot(np.log10(lasso.alphas_),mses)\n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3),[0.3,0.4,1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alpha is',lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef_lr\":list(lr.coef_.T),\"coef_ridge\":list(ridge.coef_.T),\"coef_lasso\":list(lasso.coef_.T)})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
